package com.rlovep.contact.servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.rlovep.contact.dao.ContactDao; import com.rlovep.contact.dao.impl.ContactDaoImpl; import com.rlovep.contact.entity.Contact; /** * Servlet implementation class UpdateContact */ @WebServlet("/UpdateContact") public class UpdateContact extends HttpServlet { private static final long serialVersionUID = 1L; /** * @see HttpServlet#HttpServlet() */ public UpdateContact() { super(); // TODO Auto-generated constructor stub } /** * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response) */ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding("utf-8"); //1.接收参数 String id = request.getParameter("id"); String name = request.getParameter("name"); String gender = request.getParameter("gender"); String age = request.getParameter("age"); String phone = request.getParameter("phone"); String email = request.getParameter("email"); String qq = request.getParameter("qq"); //封装成Contact对象 Contact contact = new Contact(); contact.setId(id); contact.setName(name); contact.setGender(gender); contact.setAge(Integer.parseInt(age)); contact.setPhone(phone); contact.setEmail(email); contact.setQq(qq); //2.调用dao修改联系人的方法 ContactDao dao = new ContactDaoImpl(); dao.updateContact(contact); //3.跳转到查询联系人的页面 response.sendRedirect(request.getContextPath()+"/ListContact"); } /** * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // TODO Auto-generated method stub doGet(request, response); } }